import java.util.Stack;

class ListNode{
    int value;
    ListNode next;
    public ListNode(int value) {
        this.value = value;
    }
}
public class Main {
    public ListNode swapPairs(ListNode head) {
        ListNode head1 = new ListNode(0);
        head1.next = head;
        ListNode pre = head1;

        while(pre.next!=null && pre.next.next!=null){
            ListNode cur = pre.next;
            ListNode next = cur.next;
            pre.next = next;
            cur.next = next.next;
            next.next = cur;
            pre = cur;
        }
        return head1.next;
    }

    public static String removeDuplicates(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
                if (!stack.isEmpty() && stack.peek().equals(s.charAt(i))){
                    stack.pop();
                }else {
                    stack.push(s.charAt(i));
                }
        }
        StringBuilder result = new StringBuilder();
        for (Character c : stack) {
            result.append(c);
        }
        return result.toString();
    }
    public static void main(String[] args) {
        String str = "abbaca";
        System.out.println(removeDuplicates(str));
    }
}